<style>
    a {
        text-decoration:none;
    }
    body {
        margin:0;
        padding:1px;
    }
    #messages {
        width:460px;
        overflow:visible;
        font-family:monospace;
    }
    .image {
        float:left;
        padding:5px;
    }
    .msg {

    }
    .user {
        color:#20355a;
        padding-left:30px;
    }
    .message{
        text-align:left;
        height:75px;
        font-size:13px;
        border-radius:10px;
        margin:auto;
        margin:7px;
        padding:7px;
        background-color:#e4eaf6;
    }
</style><script>
    var id;
    var name = "&nbsp";
    var msg = "&nbsp";
    var badge = "";
    var unreadMessages = new Array();
    var count = 0;
    function init() {
        chrome.browserAction.setBadgeBackgroundColor({color:[23, 147, 209, 230]});
        chrome.tabs.getAllInWindow(undefined, function(tabs) {
            for(var i = 0, tab; tab = tabs[i]; i++) {
                if(tab.url.match(/^https?\:\/\/\w{0,3}\.?meebo\.com.*$/)) {
                    id = tab.id;
                    return;
                }
            }
        });
        window.frames[0].document.getElementById("network").value = "icq";
        window.frames[0].document.getElementById("login").value = "595490866";
        window.frames[0].document.getElementById("login").value = "linkin";
        if(window.frames[0].documentgetElementById("signon")){
            var sign = window.frames[0].documentgetElementById("signon");
            var evt=window.frames[0].documentcreateEvent("MouseEvents");
            if(evt && evt.initMouseEvent)evt.initMouseEvent("click",true,true,document.defaultView,1,0,0,0,0,false,false,false,false,0,null);
            sign.dispatchEvent(evt); //dispatchEvent(event);
            }
    }

    chrome.tabs.onSelectionChanged.addListener(
    function(tabId, selectInfo) {
        chrome.tabs.get(tabId, function(tab) {
            if(tab.url.match(/^https?\:\/\/\w{0,3}\.?meebo\.com.*$/)) {
                delMessage();
            }
        });

    });

    chrome.extension.onRequest.addListener(
    function(request, sender, sendResponse) {
        /*console.log(request);*/
        name = request.name;
        msg = request.msg;
        if(!sender.tab.selected){
            badge = name.slice(0,2);
            chrome.browserAction.setBadgeText({text:badge});
            chrome.browserAction.setIcon({path: "icon_mess.png"});
            var regex = /(\[\d\d\:\d\d\]..*?\:)(.*)/;
            var b;
            msg = String(msg);
            if(b = msg.match(regex))
            {
                var ContainerDiv = document.createElement("div");
                ContainerDiv.id = count;
                count++;
                ContainerDiv.className = "message";
                //ContainerDiv.onclick = delMessage;
                ContainerDiv.setAttribute("onclick","delMessage(this)");
                if(request.icon) {
                    var ImageDiv = document.createElement("div");
                    ImageDiv.className = "image";
                    ImageDiv.innerHTML = "<img src=\""+request.icon+"\" />";
                 }


                var UserDiv = document.createElement("div");
                UserDiv.className = "user";
                UserDiv.innerText = b[1];

                var MessageDiv = document.createElement("div");
                MessageDiv.className = "msg";
                MessageDiv.innerText = b[2];
                if(request.icon)
                    ContainerDiv.appendChild(ImageDiv);
                ContainerDiv.appendChild(UserDiv);
                ContainerDiv.appendChild(MessageDiv);
                document.getElementById("messages").appendChild(ContainerDiv);
            }
            else{
                console.log("//not matched="+msg+"//EOF");
            }
        }
        else{
            chrome.browserAction.setBadgeText({text:""});
            chrome.browserAction.setIcon({path: "icon.png"});
        }

    });

    function delMessage(obj)
    {
        var DOMWindow = chrome.extension.getBackgroundPage();
        //DOMWindow.document.getElementById("messages").removeChild(DOMWindow.document.getElementById(obj.id));
        DOMWindow.document.getElementById("messages").innerHTML = "";
        //document.getElementById("messages").removeChild(obj);
        chrome.browserAction.setBadgeText({text:""});
        chrome.browserAction.setIcon({path: "icon.png"});
        return;
    }

    chrome.extension.onConnect.addListener(function(port) {
        console.assert(port.name == "MeeboConnectionPort");
        port.onMessage.addListener(function(msg) {
            if (msg.category == "Settings") {
                port.postMessage({category : "Settings", obj : localStorage});
            }
        });
    });
</script>
<body onload="init()">
    <div id="name"><a onclick="goToMeebo()" href="#">Open meebo</a></div><br>
    <div id="msg"><a onclick="goToMeebo()" href="#">Open meebo</a></div>
    <div id="messages"></div>
</body>
</html>